/**
 * 
 */
package EventHandling;

import fightSequencing.Fight;
import Entities.Entity;
import Entities.EntityType;

/**
 * @author Mark J Wood
 *
 */
public class CombatEventHandler extends AbstractEventHandler {

	@Override 
	protected String[] matchingEvent() {
		return new String[]{"hits", "Attack"}; // takes combat events from Players
	}

	@Override
	public void handleHere(String anEvent) {
		String mobType = "";
		String playerType = "";
		setTheCorrectInstanceVariables("Combat", anEvent);

		if (checkForType(subjectName).equals(EntityType.BOSSMOB) || checkForType(subjectName).equals(EntityType.ADDMOB)) {
			mobType = "subject";
			playerType = "target";
		} else {
			mobType = "target";
			playerType = "subject";
		}	

		String mobName = "";
		if (mobType.equals("subject")) {
			mobName = subjectName;
		} else {
			mobName = targetName;
		}

		if 	(findTheCorrectFight(mobName) == null) {
			localFight = new Fight();
			switch(mobType) {
			case "target" :
				player = new Entity(subjectName, checkForType(subjectName), abilityName, eventAmount, eventTime);
				mob = new Entity(targetName, checkForType(targetName), eventAmount);
				player.setCurrentDamageDone(eventAmount);
				localFight.addPlayerToGroup(player);
				localFight.setMob(mob);
				break;
			case "subject" :
				mob = new Entity(subjectName, checkForType(subjectName), abilityName, eventAmount, eventTime);
				player = new Entity(targetName, checkForType(targetName), eventAmount);
				mob.setCurrentDamageDone(eventAmount);
				localFight.addPlayerToGroup(player);
				localFight.setMob(mob);
				break;
			}
		} else {
			this.localFight = findTheCorrectFight(mobName);
			this.mob = localFight.getMob();
			switch(playerType) {
			case "target" :
				this.player = localFight.returnPlayerIfItExists(targetName);
				mob.addAbilityToDeck(abilityName, eventAmount);
				mob.setCurrentDamageDone(eventAmount);
				player.setCurrentDamageTaken(eventAmount);
				break;
			case "subject" :
				this.player = localFight.returnPlayerIfItExists(subjectName);
				player.addAbilityToDeck(abilityName, eventAmount);
				player.setCurrentDamageDone(eventAmount);
				mob.setCurrentDamageTaken(eventAmount);
				break;
			}
			this.player.setType(EntityType.PLAYER);
		}
	}
}

